package com.restaurant.application.minifacade.data;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;
import java.util.stream.Collectors;

public class BookingBO implements PickableBean {

    public static final String FN_SHOPS = "shops";
    public static final String FN_SERVICE = "service";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_SHOPS,
            FN_SERVICE);

    private List<ShopBO> shops;
    private List<String> service;

    public BookingBO(List<ShopBO> shops, List<String> service) {
        setShops(shops);
        setService(service);
    }

    public BookingBO() {
    }

    public BookingBO duplicate() {
        BookingBO result = new BookingBO();
        result.shops = this.shops == null ? null : this.shops.stream().map(e1 -> e1 == null ? null : e1.duplicate()).collect(Collectors.toList());
        result.service = this.service == null ? null : this.service.stream().map(e2 -> e2).collect(Collectors.toList());
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public List<ShopBO> getShops() {
        if (shops == null) {
            shops = Lists.newArrayList();
        }
        return shops;
    }

    public void setShops(List<ShopBO> value) {
        this.shops = value;
    }

    public BookingBO withShops(List<ShopBO> value) {
        setShops(value);
        return this;
    }

    public BookingBO withShops(List<ShopBO> value, List<ShopBO> defaultValue) {
        setShops(value == null ? defaultValue : value);
        return this;
    }

    public BookingBO addShops(ShopBO value) {
        if (shops == null) {
            shops = Lists.newArrayList();
        }
        this.shops.add(value);
        return this;
    }

    public List<String> getService() {
        if (service == null) {
            service = Lists.newArrayList();
        }
        return service;
    }

    public void setService(List<String> value) {
        this.service = value;
    }

    public BookingBO withService(List<String> value) {
        setService(value);
        return this;
    }

    public BookingBO withService(List<String> value, List<String> defaultValue) {
        setService(value == null ? defaultValue : value);
        return this;
    }

    public BookingBO addService(String value) {
        if (service == null) {
            service = Lists.newArrayList();
        }
        this.service.add(value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "shops":
                return getShops();
            case "service":
                return getService();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof BookingBO)) return false;
        return signature().equals(((BookingBO) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean BookingBO has no signature defined, no hash code or equals possible.");
    }
}
